package com.hunttown.mes.rpc.domain.enums.purchase;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 出库方式：1消耗 2借用 3退货
 * created by wangjunfu on 2018/11/6
 */
public enum PurchaseDetailOutEnum {
    USE(1, "消耗"),
    BORROW(2, "借用"),
    RETURN(3, "退货"),
    DAMAGE(4, "报废"),
    CHILD11(11, "子单出库"),
    CHILD12(12, "子单退库"),
    CHILD13(13, "解锁未使用物料");

    private final int key;
    private final String value;

    PurchaseDetailOutEnum(int key, String value) {
        this.key = key;
        this.value = value;
    }

    // 根据key获取枚举
    public static String getEnumByKey(int key) {
        String value = "";

        for (PurchaseDetailOutEnum temp : PurchaseDetailOutEnum.values()) {
            if (temp.getKey() == key) {
                value = temp.getValue();
            }
        }

        return value;
    }

    // 将枚举组成Map
    public static Map<Integer, String> getEnumList() {
        Map<Integer, String> map = new HashMap<>();

        for (PurchaseDetailOutEnum temp : PurchaseDetailOutEnum.values()) {
            map.put(temp.getKey(), temp.getValue());
        }

        return map;
    }


    // 将枚举组成Map（因为枚举是公用的，所以不同项目选择的不一样）
    public static Map<Integer, String> getEnumList(List<Integer> keys) {
        Map<Integer, String> map = new HashMap<>();

        for (PurchaseDetailOutEnum temp : PurchaseDetailOutEnum.values()) {
            if (keys.contains(temp.getKey())) {
                map.put(temp.getKey(), temp.getValue());
            }
        }

        return map;
    }

    // 功能同上
    public static Map<Integer, String> getEnumList(String keyStr) {
        Map<Integer, String> map = new HashMap<>();

        if (keyStr == null || keyStr.equals("")) {
            return map;
        }

        List<Integer> keys = new ArrayList<>();

        String[] arrKey = keyStr.split(",");
        for (String arr : arrKey) {
            keys.add(Integer.parseInt(arr));
        }

        for (PurchaseDetailOutEnum temp : PurchaseDetailOutEnum.values()) {
            if (keys.contains(temp.getKey())) {
                map.put(temp.getKey(), temp.getValue());
            }
        }

        return map;
    }

    public int getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }
}
